﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CEntidades;
using System.Data.SqlClient;
using System.Data;

namespace CDatos{
    public class dCliente{
        public static eCliente VerificarAcceso(String prmUser, String prmPass){
            eCliente objCliente = null;
            SqlCommand cmd = null;
            SqlDataReader dr = null;
            try{
                Conexion cn = new Conexion();
                SqlConnection conex = cn.conectar();
                cmd = new SqlCommand("spVerificarAcceso", conex);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@prmUsuario", prmUser);
                cmd.Parameters.AddWithValue("@prmPassword", prmPass);
                conex.Open();
                dr = cmd.ExecuteReader();
                if (dr.Read()){
                    objCliente = new eCliente();
                    objCliente.idCliente = Convert.ToInt32(dr["idCliente"]);
                    objCliente.RazonSocial = dr["RazonSocial"].ToString();
                    objCliente.direccion = dr["direccion"].ToString();
                    objCliente.Telefono = dr["Telefono"].ToString();
                    objCliente.Usuario = dr["Usuario"].ToString();
                    objCliente.Password = dr["Password"].ToString();
                }
            }
            catch (Exception e) {
                objCliente = null;
            }finally{
                cmd.Connection.Close();
            }
            return objCliente;
        }
    }
}
